<template>
  <div id="main2" style="width: 100%; height: 400px"></div>
</template>

<script>
import * as echarts from "echarts"; //引入
import { mothOrder } from "@/api/stat.js";
export default {
  data() {
    return {};
  },

  mounted() {
    mothOrder().then((res) => {
      var datArr = [];
      var orderCuntArr = [];
      console.log(res);
      res.forEach((itme) => {
        datArr.push(itme.dat);
        orderCuntArr.push(itme.cunt);
      });

      // 基于准备好的dom，初始化echarts实例
      var myChart5 = echarts.init(document.getElementById("main2"));
      // 绘制图表
      var option5 = {
        title: {
          left: "center",
          text: "每月订单数量统计",
        },
        tooltip: {},
        xAxis: {
          data: datArr,
        },
        yAxis: {},
        series: [
          {
            name: "订单数",
            type: "bar",
            data: orderCuntArr,
          },
        ],
      };

      myChart5.setOption(option5);
    });
  },
};
</script>

